package com.yeu.action;

import java.util.List;
import java.util.Map;

import com.opensymphony.xwork2.ActionSupport;
import com.yeu.util.ConnectionPool;

public class ResourceAction extends ActionSupport{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private List<Map<String, String>> result;
	private String departmentId;
	private String stud_academy;
	private String grade;
	private String major;
	private String className;
	private String gender;
	private String stud_name;
	private String teac_academy;
	private String academy_leader;
	private String reporterTeacherName;
	private String stud_id;
	
	public String getStud_id() {
		return stud_id;
	}

	public void setStud_id(String stud_id) {
		this.stud_id = stud_id;
	}
	
	public String getReporterTeacherName() {
		return reporterTeacherName;
	}

	public void setReporterTeacherName(String reporterTeacherName) {
		this.reporterTeacherName = reporterTeacherName;
	}

	public String getAcademy_leader() {
		return academy_leader;
	}

	public void setAcademy_leader(String academy_leader) {
		this.academy_leader = academy_leader;
	}

	public String getTeac_academy() {
		return teac_academy;
	}

	public void setTeac_academy(String teac_academy) {
		this.teac_academy = teac_academy;
	}

	
	
	public String getStud_name() {
		return stud_name;
	}

	public void setStud_name(String stud_name) {
		this.stud_name = stud_name;
	}

	public String getClassName() {
		return className;
	}

	public void setClassName(String className) {
		this.className = className;
	}

	public String getGender() {
		return gender;
	}

	public void setGender(String gender) {
		this.gender = gender;
	}

	public String getGrade() {
		return grade;
	}

	public void setGrade(String grade) {
		this.grade = grade;
	}

	public String getMajor() {
		return major;
	}

	public void setMajor(String major) {
		this.major = major;
	}
	
	public String getStud_academy() {
		return stud_academy;
	}

	public void setStud_academy(String stud_academy) {
		this.stud_academy = stud_academy;
	}

	public void setDepartmentId(String departmentId) {
		this.departmentId = departmentId;
	}

	public List<Map<String, String>> getResult() {
		return result;
	}

	public String classList(){
		String sql="select * from CLASS";
		result=ConnectionPool.executeQuery(sql);
		return SUCCESS;
	}
	public String classNameList(){
		//System.out.println("hello");
		String sql="select DISTINCT CLASSNAME from STUDENT where CLASSID LIKE ? and MAJOR=?";
		result = ConnectionPool.executeQuery(sql, grade+"%",major);
		//System.out.println(result);
		return SUCCESS;
	}
	
	public String departmentList(){
		String sql="select * from DEPARTMENT";
		result=ConnectionPool.executeQuery(sql);
		//System.out.println(result);
		return SUCCESS;
	}
	public String majorList(){
		String sql = "select DISTINCT MAJOR from Student where DEPARTMENTNAME=?";
		result = ConnectionPool.executeQuery(sql, stud_academy);
//		System.out.print(result);
		return SUCCESS;
	}
	//
	public String studentNameList(){
		String sql = "select STUDENTNAME from STUDENT where CLASSNAME = ? and GENDER = ?";
		result = ConnectionPool.executeQuery(sql, className,gender);
		//System.out.println(result);
		return SUCCESS;
	}
	//
	public String studentIdList(){
		String sql = "select STUDENTID from STUDENT where CLASSNAME = ? and STUDENTNAME = ?";
		result = ConnectionPool.executeQuery(sql, className,stud_name);
		//System.out.println(result);
		return SUCCESS;
	}
	public String leaderList(){
		String sql="select * from USERTABLE U,DEPARTMENTLEADER D where D.DEPARTMENTID=? and U.USERID=D.USERID";
		result=ConnectionPool.executeQuery(sql, departmentId);
		for (Map<String, String> map : result) {
			map.remove("DEPARTMENTID");
			map.remove("PASSWORD");
			map.remove("ROLEID");
		}
		return SUCCESS;
	}
	public String classLeaderInfo(){
		//List<Map<String,String>> integratedResult = new ArrayList<Map<String,String>>();
		String sql = "select CLASSMONITORNAME,CLASSDIRECTORNAME,CLASSDIRECTORPHONE from class where CLASSID in "
				+ "(select distinct CLASSID from STUDENT where CLASSNAME = ?)";
		result = ConnectionPool.executeQuery(sql, className);
		//System.out.println(result);
		return SUCCESS;
	}
	
	public String departmentLeaderList(){
		//System.out.println(teac_academy);
		String sql = "select  distinct USERNAME from department,departmentleader,usertable where department.departmentid = departmentleader.departmentid and department.departmentid = usertable.departmentid and department.departmentname=?";
		result=ConnectionPool.executeQuery(sql, teac_academy);
		//System.out.println(result);
		return SUCCESS;
	}
	public String leaderPhoneNumber(){
		String sql = "select PHONE from usertable where USERNAME = ?";
		result = ConnectionPool.executeQuery(sql, academy_leader);
		//System.out.println("phone"+result);
		return SUCCESS;
	}
	public String teacherBuilding(){
		String sql = "select BUILDING from TEACHERROOM where NAME = ?";
		result = ConnectionPool.executeQuery(sql, reporterTeacherName);
		//System.out.println(result);
		return SUCCESS;
	}
	public String teacherRoom(){
		String sql = "select ROOM from TEACHERROOM where NAME = ?";
		result = ConnectionPool.executeQuery(sql, reporterTeacherName);
		//System.out.println(result);
		return SUCCESS;
	}
	public String stuRoom(){
		String sql="select STUROOM from STUDROOM where STUDID = ?";
		result=ConnectionPool.executeQuery(sql,stud_id);
		//System.out.println(result);
		return SUCCESS;
	}
	public String getDepartmentEmp(){
		String sql="select EMPNAME from DEPARTMENTEMP where DEPARTMENTNAME = ?";
		result = ConnectionPool.executeQuery(sql, teac_academy);
		//System.out.println(result);
		return SUCCESS;
	}
}